package jvs.core.http;

/**
 *  HTTP Web Server
 *  @author qiangli
 */


import java.util.Properties;

import jvs.core.Lifecycle;
import jvs.core.http.handler.BinHandler;
import jvs.core.http.handler.FileHandler;
import jvs.vfs.FileSystem;


public class HttpServer implements Lifecycle {
	private boolean started = false;
	private HttpConnector conn;

	public HttpServer() {
	}

	synchronized public void init(Properties attrs) {
		conn = new HttpConnector();
		conn.init(attrs);
	}

	synchronized public void startup() {
		if (started) {
			try {
				shutdown();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		Adapter pi = new Adapter();
		//
		pi.addHandler(new BinHandler());
		pi.addHandler(new FileHandler());

		conn.setPI(pi);
		conn.startup();
	}

	synchronized public void shutdown() {
		conn.shutdown();
	}
	
	public static void main(String[] args) {
		String uri = new java.io.File("c:/temp").toURI().toString();
		java.lang.System.setProperty("jvs.rootfs", uri);
		java.lang.System.setProperty("jvs.debug", "trace");
		FileSystem.getFileSystem().boot();
		//
		HttpServer hs = new HttpServer();
		hs.init(null);
		hs.startup();
	}
}
